package com.spa.domain.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spa.domain.entity.DouYinOauth;
import com.spa.infrastructure.mapper.DouYinOauthMapperStruct;
import com.spa.infrastructure.repository.po.DouyinOauthPO;
import com.spa.infrastructure.repository.service.DouYinOauthRepositoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class DouYinOauthService {

    @Resource
    private DouYinOauthRepositoryService douYinOauthRepositoryService;

    /**
     * 添加抖音账号
     * @param po
     * @return
     */
    public Long addDouYinAccount(DouyinOauthPO po){
        return douYinOauthRepositoryService.addDouYinAccount(po);
    }

    public DouYinOauth getAccountById(long id) {
        return DouYinOauthMapperStruct.INSTANCE.po2Entity(douYinOauthRepositoryService.getById(id));
    }

    public DouYinOauth getByOpenId(String openId) {
        return DouYinOauthMapperStruct.INSTANCE.po2Entity(douYinOauthRepositoryService.getByOpenId(openId));
    }

    public boolean updateDouYinAccountById(DouyinOauthPO po) {
       return douYinOauthRepositoryService.updateById(po);
    }

    public Page<DouYinOauth> page(long current, long size) {
        return DouYinOauthMapperStruct.INSTANCE.po2Entity4Page(douYinOauthRepositoryService.page(Page.of(current, size)));
    }
}
